package com.shj.em.biz.sys.service;

import com.shj.em.biz.sys.entity.EmpRank;
import com.shj.em.biz.sys.mapper.EmpRankMapper;
import com.shj.em.biz.sys.service.EmpRankService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.plugins.Page;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.shj.em.util.DateUtils;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;


/**
 * 员工等级表 服务实现类
 *
 * @author Shen Huang Jian
 * @since 2018-08-08
 */
@Service
@Transactional
public class EmpRankServiceImpl extends ServiceImpl<EmpRankMapper, EmpRank> implements EmpRankService {

    @Autowired
    EmpRankMapper emprankMapper;

    public Page<EmpRank> queryEmpRankPage(Map<String, Object> params){
        int offset = (Integer)params.get("offset");
        int pageSize = (Integer)params.get("limit");
        int pageNo = offset / pageSize + 1;
        Page<EmpRank> page = new Page(pageNo, pageSize);
        List<EmpRank> list = emprankMapper.queryEmpRankPage(page, params);
        return page.setRecords(list);
    }

    public Map<Long,List<EmpRank>> findAllEmpRanks(){
        List<EmpRank> list = emprankMapper.findAllEmpRanks();
        Map<Long,List<EmpRank>> empRankMap = new HashMap<>();
        for(EmpRank er : list){
            if(!empRankMap.containsKey(er.getEmpId())){
                empRankMap.put(er.getEmpId(), new ArrayList<>());
            }
            empRankMap.get(er.getEmpId()).add(er);
        }
        return empRankMap;
    }

}
